﻿using System;

namespace Chess.Common.Network
{
    [Serializable]
    public class Version
    {
        public int Major;
        public int Minor;
        public int Revision;

        public Version() {}

        public Version(int major, int minor, int revision)
        {
            Major = major;
            Minor = minor;
            Revision = revision;
        }

        public bool Equals(Version other)
        {
            if (ReferenceEquals(null, other)) return false;
            if (ReferenceEquals(this, other)) return true;
            return other.Major == Major && other.Minor == Minor && other.Revision == Revision;
        }

        public override bool Equals(object obj)
        {
            if (ReferenceEquals(null, obj)) return false;
            if (ReferenceEquals(this, obj)) return true;
            if (obj.GetType() != typeof (Version)) return false;
            return Equals((Version) obj);
        }

        public override int GetHashCode()
        {
            unchecked
            {
                int result = Major;
                result = (result*397) ^ Minor;
                result = (result*397) ^ Revision;
                return result;
            }
        }
    }

    [Serializable]
    public class HandshakePacket : NetworkData
    {
        public override object Id
        {
            get { return "handshake"; }
        }

        public Version Version { get; set; }

        public HandshakePacket() {}

        public HandshakePacket(Version version)
        {
            Version = version;
        }
    }
}
